home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 2 / The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO / clang / dtk_demo.zip / DATEFORM.C < prev    next >
C/C++ Source or Header  |  1991-09-12  |  3KB  |  151 lines

  1. /*  DATEFORM.C
  2.  *  last mod.: 10-AUG-91
  3.  */
  4.  
  5. /*  this displays a given date 54 times
  6.  *  using different date format parameters;
  7.  *  in a few cases different parameters produce
  8.  *  the same result;
  9.  *  output can be redirected to printer or disk file
  10.  */
  11.  
  12. #include <STDIO.H>
  13. #include <STDLIB.H>
  14. #include <CONIO.H>
  15. #include <STRING.H>
  16.  
  17. /*#include <L_FILE.H>*/
  18. #include <L_MISC.H>
  19. #include <L_DATE.H>
  20. #include <L_STR.H>
  21.  
  22. char *usage = "\nUse DATEFORM month day year\n";
  23. char *prompt = "Press a key ... ";
  24. char date_str[64];
  25. Date dt;
  26. Date_format df;
  27. int n=0;
  28. char backspaces[20];
  29.  
  30. void main(int argc, char *argv[]);
  31. void display_dates(void);
  32. void display_date(void);
  33.  
  34. /*-----------------------------*/
  35. void main(int argc, char *argv[])
  36. {
  37. if ( argc < 4 )
  38.     {
  39.     printf(usage);
  40.     exit(0);
  41.     }
  42.  
  43. dt.month = atoi(argv[1]);
  44. dt.day = atoi(argv[2]);
  45. dt.year = atol(argv[3]);
  46.  
  47. if ( !date_valid(&dt) )
  48.     {
  49.     printf("\nInvalid date.\n");
  50.     exit(1);
  51.     }
  52.  
  53. string(backspaces,'\b',strlen(prompt));
  54. set_date_format_default(&df);
  55. for ( df.short_year=TRUE; df.short_year>=FALSE; df.short_year-- )
  56.     {
  57.     for ( df.justify=FALSE; df.justify<=TRUE; df.justify++ )
  58.         {
  59.         if ( !df.justify )
  60.             {
  61.             for ( df.suffix=FALSE; df.suffix<=TRUE; df.suffix++ )
  62.                 display_dates();
  63.             }
  64.         else
  65.             {
  66.             df.suffix = FALSE;
  67.             display_dates();
  68.             }
  69.         }
  70.     }
  71. }
  72.  
  73. /*--------------------*/
  74. void display_dates(void)
  75. {
  76. df.full_month_name = FALSE;
  77. df.short_month_name = FALSE;
  78. df.full_day_name = FALSE;
  79. df.short_day_name = FALSE;
  80. display_date();
  81.  
  82. df.full_month_name = FALSE;
  83. df.short_month_name = FALSE;
  84. df.full_day_name = FALSE;
  85. df.short_day_name = TRUE;
  86. display_date();
  87.  
  88. df.full_month_name = FALSE;
  89. df.short_month_name = FALSE;
  90. df.full_day_name = TRUE;
  91. df.short_day_name = FALSE;
  92. display_date();
  93.  
  94. df.full_month_name = FALSE;
  95. df.short_month_name = TRUE;
  96. df.full_day_name = FALSE;
  97. df.short_day_name = FALSE;
  98. display_date();
  99.  
  100. df.full_month_name = FALSE;
  101. df.short_month_name = TRUE;
  102. df.full_day_name = FALSE;
  103. df.short_day_name = TRUE;
  104. display_date();
  105.  
  106. df.full_month_name = FALSE;
  107. df.short_month_name = TRUE;
  108. df.full_day_name = TRUE;
  109. df.short_day_name = FALSE;
  110. display_date();
  111.  
  112. df.full_month_name = TRUE;
  113. df.short_month_name = FALSE;
  114. df.full_day_name = FALSE;
  115. df.short_day_name = FALSE;
  116. display_date();
  117.  
  118. df.full_month_name = TRUE;
  119. df.short_month_name = FALSE;
  120. df.full_day_name = FALSE;
  121. df.short_day_name = TRUE;
  122. display_date();
  123.  
  124. df.full_month_name = TRUE;
  125. df.short_month_name = FALSE;
  126. df.full_day_name = TRUE;
  127. df.short_day_name = FALSE;
  128. display_date();
  129. }
  130.  
  131. /*-------------------*/
  132. void display_date(void)
  133. {
  134. date_to_str(&dt,&df,date_str);
  135. pad_on_right(date_str,' ',39);
  136. printf("%s",date_str);
  137. if ( ++n%2 )
  138.     putchar(' ');
  139. else
  140.     putchar('\n');
  141. if ( !output_redirected() )
  142.     {
  143.     if ( n == 46 )
  144.         {
  145.         cputs(prompt);
  146.         getch();
  147.         cputs(backspaces);
  148.         }
  149.     }
  150. }
  151.